// pages/myself/address/newaddress.js
var utils = require('../../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        region: ["福建省", "厦门市", "湖里区"],
        name: "",
		address:"",
		phone:"",
        ismoren: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
		if (options.id){
			wx.setNavigationBarTitle({
				title: '编辑收货地址',
			})
			var that = this
			utils.GET({
				url: 'Cart/savechoose',
				params: {
					id: options.id,
				},
				success: function (res) {
					that.setData({
						region: res.data.city,
						name: res.data.name,
						phone: res.data.phone,
						address: res.data.xxdz
					})
					console.log(res.data)
				},
			})
		}


    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },
    bindRegionChange: function(e) {
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            region: e.detail.value
        })
    },
    morentap: function() {
        var that = this
        var ismoren = that.data.ismoren
        ismoren = !ismoren
        that.setData({
            ismoren: ismoren
        })
    },
    nametap: function(e) {
       var that=this
	   that.setData({
		   name:e.detail.value
	   })
    },
	phonetap: function (e) {
		var that = this
		that.setData({
			phone: e.detail.value
		})
	},
	addresstap: function (e) {
		console.log(e)
		var that = this
		that.setData({
			address: e.detail.value
		})
	},
    savetap: function() {
        var that = this
		var city = that.data.region
		var name = that.data.name
		var phone = that.data.phone
		var address = that.data.address
		if (name.length < 1) {
			wx.showToast({
				title: '请输入收货人姓名',
			})
			return;
		} else if (phone.length < 1) {
			wx.showToast({
				title: '请输入收货人手机',
			})
			return;
		} else if (city.length < 1) {
			wx.showToast({
				title: '请输入省市区',
			})
			return;
		} else if (address.length < 1) {
			wx.showToast({
				title: '请输入收货人详细地址',
			})
			return;
		}else{
        utils.GET({
			url: 'Cart/addAddr',
            params: {
				city: city,
				name:name,
				address: address,
				phone:phone
			},
            success: function(res) {
                console.log(res.data)
				wx.navigateBack();
            },
        })
		}
    }
})